<template>
	<div class="content">
		<div class="clear">
			<!--<div class="add" style="float:right;">
				全球加权总奖池：<span v-text="look">12123213</span>
			</div>-->
			<Form inline class="fl">
				<Input type="text" placeholder="受益者UUID" class="w200 m-r10" v-model.trim="userid" />
				<Input type="text" placeholder="受益者手机号码" class="w200 m-r10" v-model.trim="phone" />
				<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd" @on-change="getTime">
				</DatePicker>
				<Button type="primary" v-on:click="ifGetQuery">查询</Button>
			</Form>
		</div>
		<Button class="daochu" type="primary" size="large" @click="exportData" :loading="dcShow">
            <Icon type="ios-download-outline"></Icon> 导出
		</Button>
		<Table stripe :columns="columns" ref="table" :data='list' :loading="loading"></Table>
		<Page :total="info" show-elevator :page-size="pageSize" show-total @on-change="cuctGetQuery" :current.sync="page"></Page>
		<Modal v-model="modal1" title="奖励记录" width='55%'>
			<Input type="text" placeholder="受益者UUID" class="w200 m-r10" v-model.trim="userid2" />
			<Input type="text" placeholder="受益者手机号码" class="w200 m-r10" v-model.trim="phone2" />
			<DatePicker type="daterange" split-panels placeholder="请选择时间段" class="w200 m-r10" format="yyyy-MM-dd" @on-change="getTime2">
			</DatePicker>
			<Button type="primary" v-on:click="ifGetQuery2">查询</Button>
			<Table class="m-t10" stripe :columns="columns1" :data='list1' :loading="loading2"></Table>
			<Page :total="info2" show-elevator :page-size="pageSize2" show-total @on-change="cuctGetQuery2" :current.sync="page2"></Page>
		</Modal>
	</div>
</template>
<script>
	export default {
		data() {
			return {
				loading: true,
				loading2: true,
				dcShow: false,
				jsonData: [],
				list: [], // 间接分享收益列表数据
				num: '', // 累计间接分享收益
				info: null, // 总条数
				info2: null, // 流水总条数
				page: 1, // 页数
				page2: 1, // 流水页数
				pageSize: 20, // 每页多少条
				pageSize2: 10, // 流水每页多少条
				current: 1,
				downList: [], //导出列表
				dataValue: ['', ''], // 时间段值
				dataValue2: ['', ''], // 流水时间段值
				userid: '', // 用户 ID
				userid2: '', // 流水用户 UUID
				memberId: '', // 流水用户 ID
				phone: '',
				phone2: '', //流水手机号查询
				modal1: false, //流水modal
				list1: [], //流水列表
				look: '', //全球加权总奖池
				columns: [{
						title: '受益者UUID',
						align: 'center',
						key: 'uuid',
						render: (h, params) => {
							return h('div', params.row.uuid == null ? '#' : params.row.uuid)
						}
					},
					{
						title: '受益者手机号码',
						align: 'center',
						key: 'mobile',
						render: (h, params) => {
							return h('div', params.row.mobile == null ? '#' : params.row.mobile)
						}
					},
					{
						title: '累计收益数量(ATM)',
						align: 'center',
						key: 'sumAward',
						render: (h, params) => {
							return h('div', params.row.sumAward == null ? '#' : this.Fixed(params.row.sumAward))
						}
					},
					{
						title: '收益时间',
						align: 'center',
						key: 'createTime',
						sortable: true,
						render: (h, params) => {
							return h('div', params.row.createTime == null ? '#' : this.stringToTime(params.row.createTime))
						}
					},
					{
						title: '查看流水',
						align: 'center',
						key: 'createTime',
						render: (h, params) => {
							return h(
								'div', {
									style: {
										cursor: 'pointer',
										color: '#2db7f5'
									},
									on: {
										click: () => {
											this.modal1 = true;
											this.loading2 = true;
											this.axios.post('/admin/statistical/earnings/rewardDetailInfo', this.qs.stringify({
												current: this.page2,
												size: this.pageSize2,
												memberId: params.row.id,
												uuid: this.userid2,
												mobile: this.phone2,
												startTime: this.dataValue2[0] == "" ? "" : this.dataValue2[0] + ' 00:00:00',
												endTime: this.dataValue2[1] == "" ? "" : this.dataValue2[1] + ' 23:59:59'
											})).then(res => {
												if(res.data.code == 200) {
													this.memberId = params.row.id;
													this.list1 = res.data.data.records;
													this.info2 = res.data.data.total;
													this.loading2 = false;
												}
											})
										}
									}
								},
								'查看流水'
							)
						}
					}
				],
				columns1: [{
						title: 'UUID',
						align: 'center',
						key: 'uuid',
						render: (h, params) => {
							return h('div', params.row.uuid == null ? '#' : params.row.uuid)
						}
					},
					{
						title: '手机号码',
						align: 'center',
						key: 'mobile',
						render: (h, params) => {
							return h('div', params.row.mobile == null ? '#' : params.row.mobile)
						}
					},
					{
						title: '方向',
						align: 'center',
						key: 'typeId',
						render: (h, params) => {
							return h('div', params.row.typeId == null ? '#' : params.row.typeId == '0' ? '买入' : params.row.typeId == '1' ? '卖出' : params.row.typeId == '3' ? '超级' : '#')
						}
					},
					{
						title: '交易数量',
						align: 'center',
						key: 'tradeNum',
						render: (h, params) => {
							return h('div', params.row.tradeNum == null ? '#' : this.Fixed(params.row.tradeNum))
						}
					},
					//					{
					//						title: '受益者等级',
					//						align: 'center',
					//						key: 'rewardType',
					//						render: (h, params) => {
					//							return h('div', params.row.rewardType == null ? '#' : params.row.rewardType == '1' ? '社区节点' : params.row.rewardType == '' ? '超级节点' : params.row.rewardType * 10)
					//						}
					//					},
					{
						title: '手续费',
						align: 'center',
						key: 'fee',
						render: (h, params) => {
							return h('div', params.row.fee == null ? '#' : this.Fixed(params.row.fee))
						}
					},
					{
						title: '收益比例',
						align: 'center',
						key: 'rewardRatio',
						render: (h, params) => {
							return h('div', params.row.rewardRatio == null ? '#' : params.row.rewardRatio * 100 + '%')
						}
					},
					{
						title: '收益数量',
						align: 'center',
						key: 'rewardNum',
						render: (h, params) => {
							return h('div', params.row.rewardNum == null ? '#' : this.Fixed(params.row.rewardNum))
						}
					},
					{
						title: '所属代数',
						align: 'center',
						key: 'layer',
						render: (h, params) => {
							return h('div', params.row.layer == null ? '#' : params.row.layer)
						}
					},
					{
						title: '订单时间',
						align: 'center',
						key: 'createTime',
						render: (h, params) => {
							return h('div', params.row.createTime == null ? '#' : this.stringToTime(params.row.createTime))
						}
					},
				],
			}
		},
		created() {

		},
		mounted() {
			this.$Message.config({
				top: 250
			})
			this.getQuery() // 查询业绩奖励
//			this.axios.get('/admin/statistical/integral/giving/pool').then(res => {
//				if(res.data.code == 200) {
//					this.look = res.data.data + ' ATM';
//				}
//			})
		},
		methods: {
			exportData() {
				this.jsonData = [];
				this.dcShow = true;
				this.axios.post('/admin/statistical/earnings/rewardDetail', this.qs.stringify({
					current: 1, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					uuid: this.userid, // 用户 ID
					mobile: this.phone,
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})).then(res => {
					if(res.data.code == 200) {
						this.axios.post('/admin/statistical/earnings/rewardDetail', this.qs.stringify({
							current: 1, // 当前页【可选，默认1】
							size: res.data.data.total, // 每页记录数【可选，默认20】
							uuid: this.userid, // 用户 ID
							mobile: this.phone,
							startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
							endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
						})).then(res => {
							if(res.data.code == 200) {
								this.downList = res.data.data.records;
								this.downList.forEach((row, index) => {
									this.downList[index].createTime = this.downList[index].createTime == '' ? '#' : this.stringToTime(this.downList[index].createTime);
									this.downList[index].uuid = this.downList[index].uuid == '' ? '#' : this.downList[index].uuid;
									this.downList[index].mobile = this.downList[index].mobile == '' ? '#' : this.downList[index].mobile;
									this.downList[index].sumAward = this.downList[index].sumAward == '' ? '#' : this.Fixed(this.downList[index].sumAward);
									this.jsonData.push({
										uuid: this.downList[index].uuid,
										mobile: this.downList[index].mobile,
										sumAward: this.downList[index].sumAward,
										createTime: this.downList[index].createTime,
									})
								})
								let str = `受益者UUID,受益者手机号码,累计收益数量(ATM),收益时间\n`;
								this.downLoad(this.jsonData, str, '动态收益');
							}
						})
					}
				})
			},
			// 处理时间段时间格式
			getTime(daterange) {
				this.dataValue = daterange;
			},
			// 处理时间段时间格式
			getTime2(daterange) {
				this.dataValue2 = daterange;
			},
			getQuery() {
				this.loading = true;
				let params = this.qs.stringify({
					current: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					uuid: this.userid, // 用户 ID
					mobile: this.phone,
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})
				this.axios.post('/admin/statistical/earnings/rewardDetail', params).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.loading = false;
						this.info = res.data.data.total;
					}
				})
			},
			cuctGetQuery(page) { // 分页查询业绩奖励
				this.loading = true;
				let params = this.qs.stringify({
					current: page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					uuid: this.userid, // 用户 ID
					mobile: this.phone,
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})
				this.axios.post('/admin/statistical/earnings/rewardDetail', params).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.loading = false;
						this.info = res.data.data.total;
					}
				})
			},
			cuctGetQuery2(page) { // 分页查询业绩奖励
				this.loading2 = true;
				this.axios.post('/admin/statistical/earnings/rewardDetailInfo', this.qs.stringify({
					current: page,
					size: this.pageSize2,
					memberId: this.memberId,
					uuid: this.userid2,
					mobile: this.phone2,
					startTime: this.dataValue2[0] == "" ? "" : this.dataValue2[0] + ' 00:00:00',
					endTime: this.dataValue2[1] == "" ? "" : this.dataValue2[1] + ' 23:59:59'
				})).then(res => {
					if(res.data.code == 200) {
						this.list1 = res.data.data.records;
						this.info2 = res.data.data.total;
						this.loading2 = false;
					}
				})
			},
			ifGetQuery() { // 条件查询业绩奖励
				this.loading = true;
				this.page = 1;
				let params = this.qs.stringify({
					current: this.page, // 当前页【可选，默认1】
					size: this.pageSize, // 每页记录数【可选，默认20】
					uuid: this.userid, // 用户 ID
					mobile: this.phone,
					startTime: this.dataValue[0] == "" ? "" : this.dataValue[0] + ' 00:00:00',
					endTime: this.dataValue[1] == "" ? "" : this.dataValue[1] + ' 23:59:59'
				})
				this.axios.post('/admin/statistical/earnings/rewardDetail', params).then(res => {
					if(res.data.code == 200) {
						this.list = res.data.data.records;
						this.loading = false;
						this.info = res.data.data.total;
					}
				})
			},
			ifGetQuery2() { // 条件查询业绩奖励
				this.loading2 = true;
				this.page2 = 1;
				this.axios.post('/admin/statistical/earnings/rewardDetailInfo', this.qs.stringify({
					current: this.page2,
					size: this.pageSize2,
					memberId: this.memberId,
					uuid: this.userid2,
					mobile: this.phone2,
					startTime: this.dataValue2[0] == "" ? "" : this.dataValue2[0] + ' 00:00:00',
					endTime: this.dataValue2[1] == "" ? "" : this.dataValue2[1] + ' 23:59:59'
				})).then(res => {
					if(res.data.code == 200) {
						this.list1 = res.data.data.records;
						this.info2 = res.data.data.total;
						this.loading2 = false;
					}
				})
			},
		}
	}
</script>